home *** CD-ROM | disk | FTP | other *** search
- /*
- DRIVER.C
- by Paul S. Hirose, 1990 Nov 12
- main module for the SEESAT satellite tracking program.
-
- This file is in the public domain.
-
- 0 - 99
-
- library functions and #defines used in this file:
- atof() exit() fabs() NULL printf() strcmp()
- */
-
- #include "B:SEESAT.H" /* global header */
-
- extern void exit(), printf();
- extern int strcmp();
- extern double atof(), fabs();
-
- /* used in main(), part of startup message */
- #define VERS "1990 Nov 12"
-
- /*##################### STATIC FUNCTIONS #####################*/
-
- static void
- aop(), b(), bye(), center(), e(), help(), inc(), init(), ma(), mm(),
- offset(), prnval(), raan(), run(), span(), start(), step(), stop();
-
- static double elmod();
-
- /*############################## DATA ##############################*/
-
- static double
- tf, /* end of prediction run */
- delt, /* time interval between predictions */
- tspan; /* length of run */
-
- static struct jdtim t1; /* holds either START or CENTER value */
-
- static void (*model)() = sgp4; /* ptr to prediction model */
-
- struct comd {
- char *name; /* name of command */
- void (*funp)(); /* ptr to function that executes it */
- };
-
- static struct comd comds[] = {
- {"STEP", step},
- {"START", start},
- {"STOP", stop},
- {"SPAN", span},
- {"CENTER", center},
- /* these commands are in READEL.C */
- {"INDEX", index},
- {"LOAD", load},
- {"OPEN", opn},
- /* ASTRO.C */
- {"PARA", parall},
- {"SUN", dusk},
- {"MOON", moon},
- #if ENPRE
- {"PRECESS", setep},
- #endif
- /* in this file */
- {"AOP", aop},
- {"B", b},
- {"E", e},
- {"I", inc},
- {"MA", ma},
- {"MM", mm},
- {"OFFSET", offset},
- {"RAAN", raan},
-
- {"HELP", help},
- {"EXIT", bye},
- {NULL}
- };
-
- static int cspan; /* flag; 1 = CENTER/SPAN mode */
-
- static char *nullp = NULL; /* constant */
-
- /*############################## CODE ##############################*/
-
- main()
- {
- char *cp1, *cp2;
- struct comd *comdp;
-
- ETEST((0, 1, 3, &pi)); /* dummy call to get control of brkpt */
-
- printf("SEESAT %s by Paul S. Hirose\n\n", VERS);
-
- init(); /* initialize constants */
- zd = topos(); /* get observer's coordinates, set time zone */
- printf("\ntype HELP to see commands\n");
-
- /* Execution is vectored back here for all errors */
- SETJMP(reset);
-
- tokp = &nullp; /* clear command line */
-
- for (;;) { /* main loop */
-
- while (*tokp == NULL)
- /* command line is empty */
- tok(); /* input new cmd line */
-
- cp1 = *tokp; /* point to current command */
-
- /* Find the command in the comds[] table, execute the
- corresponding function */
-
- for (comdp = comds; (cp2 = comdp->name) && strcmp(cp1, cp2);
- ++comdp)
- ;
- if (cp2) /* found command; execute */
- (*comdp->funp)();
- else {
- printf("%s: INVALID COMMAND\n", cp1);
- LONGJMP(reset, 1);
- } } }
-
-
- static void
- aop() /* alter argument of the perigee */
- {
- omegao = elmod() * de2ra;
- }
-
-
- static void
- b() /* alter bstar */
- {
- bstar = elmod();
- }
-
-
- static void
- bye()
- {
- hfree(); /* release index space */
- exit(0);
- }
-
-
- static void
- center()
- {
- tokjum(&t1); /* load t1 with CENTER value */
- cspan = 1; /* center/span mode */
- run();
- }
-
-
- static void
- e() /* alter eccentricity */
- {
- eo = elmod();
- }
-
-
- static double
- elmod()
- /* tasks common to nearly all commands that modify orbital elements */
- {
- tokp += 2; /* point to next command */
- iflag = 1; /* since elements will be altered */
- return atof(*(tokp - 1));
- }
-
-
- static void
- help()
- {
- ++tokp; /* advance to next command */
- printf("\nOFFSET/SPAN/STEP <time>\n");
- printf(" <time> = hhmm:ss.s...\n");
- printf(" leading zeros : and seconds . and decimal seconds\n");
- printf(" are optional. Minus sign allowed on OFFSET argument\n\n");
-
- #if ENPRE
- printf("CENTER/MOON/PARA/PRECESS/START/STOP/SUN <date> <time>\n");
- #else
- printf("CENTER/MOON/PARA/START/STOP/SUN <date> <time>\n");
- #endif
- printf(" e.g., START 1990 JUN 9 2100\n");
- printf(" Omit y, y/m, or y/m/d for default to last value\n\n");
-
- printf("OPEN <file name>\n");
- printf("LOAD <satellite name>\n\n");
-
- printf("MM <revs per day>\n");
- printf("E <eccentricity>\n");
- printf("AOP/I/MA/RAAN <degrees>\n");
- printf("B <bstar>\n\n");
-
- printf("EXIT/HELP/INDEX take no arguments\n\n");
- }
-
-
- static void
- inc() /* alter inclination */
- {
- xincl = elmod() * de2ra;
- }
-
-
- static void
- init()
- /* Initialize 3rd & 4th gravitational zonal harmonics. Must be done at run
- time because my compiler (Ecosoft 3.50 for CP/M) won't allow negative
- initializers! */
- {
- xj3 = -.253881e-5;
- xj4 = -1.65597e-6;
- }
-
-
- static void
- ma() /* alter mean anomaly */
- {
- xmo = elmod() * de2ra;
- }
-
-
- static void
- mm() /* alter mean motion */
- {
- xno = elmod() * twopi / xmnpda; /* radians/min */
- }
-
-
- static void
- offset()
- /* Apply a time offset to epoch of elements */
- {
- toffs = atomin(*++tokp);
- ++tokp; /* point to next cmd */
- /* Do not set iflag since initialization is independent of time */
- }
-
-
- static void
- prnval(time)
- double time; /* local time */
- /* All tabular data from a prediction run is printed here. Except for local
- time of day, all data comes from global variables in SEESAT.H. */
- {
- char **cpp;
-
- /* time, azimuth, elevation. */
- printf("%s %3d%3d ", timstr(time),
- (int) (azel.x * ra2de + .5), (int) (azel.y * ra2de + .5));
-
- /* Right Ascension, declination. */
- cpp = degdms(2, radec.x / twopi * 24.);
- printf("%2sh%2sm ", cpp[0], cpp[1]);
- cpp = degdms(1, radec.y * ra2de);
- printf("%3s %2s' ", cpp[0], cpp[1]);
-
- /* slant range, sun elevation at satellite */
- printf("%5ld %3d ", (long int) (radec.z * xkmper), elsusa);
-
- /* altitude */
- printf("%5ld ", (long int) (latlon.z * xkmper));
-
- /* latitude */
- printf("%2d%c ", (int) (fabs(latlon.y) * ra2de + .5),
- (latlon.y >= 0.) ? 'N' : 'S');
-
- /* longitude */
- printf("%3d%c\n", (int) (fabs(latlon.x) * ra2de + .5),
- (latlon.x >= 0.) ? 'E' : 'W');
- }
-
-
- static void
- raan() /* alter Right Ascension of Ascending Node */
- {
- xnodeo = elmod() * de2ra;
- }
-
-
- static void
- run()
- /* Execute prediction run. A call of this function is the last statement in
- start(), stop(), step(), span(), and center(). If there's nothing else in
- the command line to process, then automatically begin a prediction run.
- Otherwise, return without taking any action. */
- {
- double tsince, mins, temp;
- long int jd;
- unsigned int count;
-
- if (*tokp) /* haven't reached end of cmd line yet */
- return;
-
- if (delt <= 0.) {
- printf("STEP MUST BE > 0\n");
- LONGJMP(reset, 1);
- }
- jd = t1.jd;
- mins = t1.time;
- /* jd & mins are local time */
-
- tsince = t1.jd * xmnpda - 720. + t1.time + zd - epoch;
-
- if (cspan) {
- /* tsince = (center of run) - (elements epoch) */
- temp = .5 * tspan;
- mins -= temp;
- while (mins < 0.) { /* start on previous day */
- mins += xmnpda;
- --jd;
- } tsince -= temp;
- } else {
- /* tsince = (start of run) - (elements epoch) */
- if (tf - epoch < tsince) {
- printf("START TIME IS AFTER STOP TIME\n");
- LONGJMP(reset, 1);
- } tspan = tf - (epoch + tsince);
- }
- count = tspan / delt + 1.95;
- printf("%s ", name); /* satellite name */
- printf("%s", jdstr(jd)); /* print date */
- if (toffs)
- printf(" offset = %s", timstr(toffs));
- printf("\n");
- printf(" time az el R.A. dec range sun alt l\
- at lon\n");
-
- do {
- if (mins >= xmnpda) { /* crossed midnight */
- mins -= xmnpda;
- printf("%s\n", jdstr(++jd)); /* print new date */
- }
- FTEST((1, 1, 2, &tsince));
- (*model)(tsince - toffs); /* call prediction model */
- DTEST((2, 1, &elsusa));
- if (xyztop(tsince + epoch)) {
- /* above horizon; print line of data */
- FTEST((3, 1, 2, &mins));
- prnval(mins);
- } mins += delt;
- tsince += delt;
- } while (--count);
- }
-
-
- static void
- span()
- {
- tspan = atomin(*++tokp);
- ++tokp; /* point to next command */
- cspan = 1; /* center/span mode */
- run();
- }
-
-
- static void
- start()
- {
- tokjum(&t1); /* load struct with START time */
- cspan = 0; /* start/stop mode */
- run();
- }
-
-
- static void
- step()
- {
- delt = atomin(*++tokp);
- ++tokp; /* point to next command */
- run();
- }
-
-
- static void
- stop()
- {
- tf = tokmin();
- cspan = 0; /* start/stop mode */
- run();
- }
- t =